Python is well suited to perform basic arithmetic and is well supplemented by the numpy and scipy libraries.
By the end of this file you should have seen simple examples of:
Further Reading:
https://docs.python.org/2/library/math.html#power-and-logarithmic-functions
https://docs.python.org/2/library/math.html#trigonometric-functions
In [1]:
# Python Imports
import math
In [2]:
print('The sum of 3 and 4 is: {0}'.format(3 + 4))
print('The product of 3 and 4 is: {0}'.format(3 * 4))
print('The difference of 3 with 4 is: {0}'.format(3 - 4))
print('The dividend of 3 with 4 is: {0}'.format( 3 / 4))
print('The modulo of 3 with 4 is: {0}'.format(3 % 4))
In [3]:
# Powers and roots
print('The power of 3 to the 4 is: {0}'.format(3 ** 4))
print('The 3rd root of 4 is: {0}'.format(4 ** (1.0 / 3)) )
In [4]:
#Logarithmic functions
print('The log base 10 of 3 is: {0}'.format(math.log10(3)) )
print('The log base e of 3 is: {0}'.format(math.log(3)) )
print('The log base 3 of 4 is: {0}'.format(math.log(4,3)) )
In [5]:
# Trigonometric functions
print('The sine of pi is: {0}'.format(math.sin(math.pi)) )
print('The sine of pi is: {0}'.format(math.cos(math.pi)) )
print('The arc tangent of pi is: {0}'.format(math.atan(math.pi)) )